<!--
 * @Author: QUAN
 * @Date: 2021-10-29 15:34:55
 * @LastEditTime: 2021-11-05 14:29:18
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \mutong-ketang-pc-mis\src\views\Activity\ActList.vue
-->
<template>
  <div class="comp-list">
    <search-list
      ref="complist"
      :api-url="$url.SaleLotteryList"
      :option="searchOpt"
      :itemPerRow="6"
      :beforeQuery="beforeQuery"
      @selection-change="selectionChange"
    >
      <el-table-column type="selection"></el-table-column>
      <el-table-column prop="lotteryId" label="组件ID"></el-table-column>
      <el-table-column prop="endTime" label="开奖日期"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="detail(scope.row)">编辑</el-button>
          <el-button type="text" @click="deleteCompItem(scope.row)">删除</el-button>
        </template>
      </el-table-column>
      <div slot="btn-after" class="btn-after">
        <el-button type="success" @click="add" class="el-icon-plus">
          新建抽奖组件
        </el-button>
      </div>
    </search-list>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        // 多选
        selectedData: [],
        // 筛选
        searchOpt: [
          {
            type: this.SEARCH_COMP_ENUM.SEARCH_INPUT,
            name: 'lotteryId',
            label: '组件ID',
          },
          {
            type: this.SEARCH_COMP_ENUM.SEARCH_DATEPICKER,
            name: 'updatedAt',
            label: '开奖日期',
            conf: {
              type: 'datetimerange',
              format: 'yyyy-MM-dd HH:mm:ss',
              'value-format': 'yyyy-MM-dd HH:mm:ss',
              'start-placeholder': '开始时间',
              'end-placeholder': '结束时间',
            },
          },
        ],
      };
    },
    created() {},
    mounted() {},
    methods: {
      // 删除
      deleteCompItem(item) {
        this.$confirm('确定要删除这个抽奖组件吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            this.$service.SaleLotteryDelete({ id: item.id }).then((res) => {
              this.$message.success('删除成功！');
              this.$refs.complist.getList();
            });
          })
          .catch(() => {});
      },

      // 详情
      detail(item) {
        const { id } = item;
        this.$tabs.open({ name: 'ActivityCompDetail', params: { id } });
      },

      // 新增
      add() {
        this.$tabs.open({ name: 'ActivityCompDetail' });
      },

      // 多选
      selectionChange(val) {
        this.selectedData = [...val];
      },

      // 筛选之前
      beforeQuery({ searchInfo }) {
        if (searchInfo.updatedAt === null) {
          searchInfo.startTime = '';
          searchInfo.endTime = '';
        } else {
          searchInfo.startTime = searchInfo.updatedAt[0];
          searchInfo.endTime = searchInfo.updatedAt[1];
        }
      },
    },
  };
</script>
<style lang="less" scoped>
  .comp-list {
  }
</style>
